This example shows how you can use a PyQt6 QListView
to display a list.
It simply shows a static list of strings. Technically, the data is managed by Qt's QStringListModel
. The important steps of the code are:
model = QStringListModel(["An element", "Another element", "Yay! Another one."])
view = QListView()
view.setModel(model)
view.show()
This is very similar to the previous example, where we displayed a tree view of files. The reason for this similarity is that both examples use Qt's Model/View framework. As an exercise for yourself, you might want to try using QListView
instead of QTreeView
in the previous example.
To run this example, please follow the instructions in the README of this repository.